package com.lagou.homework;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class HomeworkOutputFormat extends FileOutputFormat<Bean, NullWritable> {

    @Override
    public RecordWriter<Bean, NullWritable> getRecordWriter(TaskAttemptContext taskAttemptContext)
            throws IOException, InterruptedException {

        Configuration conf = taskAttemptContext.getConfiguration();
        FileSystem fs = FileSystem.get(conf);

        FSDataOutputStream out = fs.create(new Path("F:\\homework_output\\result.txt"));

        HomeworkWriter commentWriter = new HomeworkWriter(out);
        return commentWriter;
    }
}
